namespace Legend.Core.Tests
{
    using System;
    using System.Globalization;
    using Legend.Tests;
    using NUnit.Framework;

    [TestFixture]
    public class SystemTimeTests
    {
        [TestCase("2010-01-01")]
        [TestCase("2010-02-01")]
        public void Should_get_the_time_provided_by_the_current_provider(string currentTime)
        {
            // Arrange
            var parsedTime = DateTime.Parse(currentTime, CultureInfo.InvariantCulture);
            SystemTimeProvider provider = () => parsedTime;

            // Act
            using (SystemTime.SetCurrentProvider(provider))
            {
                // Assert
                Assert.That(SystemTime.Now, Is.EqualTo(parsedTime));
            }
        }

        [Test]
        public void Should_reset_the_original_provider_when_disposing_returned_disposable()
        {
            // Arrange
            using (SystemTime.SetCurrentProvider(() => DateTime.MinValue))
            {
                // Act
                using (SystemTime.SetCurrentProvider(() => DateTime.MaxValue))
                { }

                // Assert
                Assert.That(SystemTime.Now, Is.EqualTo(DateTime.MinValue));
            }
        }

        [Test]
        public void SetCurrentProvider_should_be_null_guarded()
        {
            // Arrange

            // Act

            // Assert
            NullGuardedConstraint.Assert(() =>
                SystemTime.SetCurrentProvider(() => DateTime.MinValue));
        }
    }
}
